package com.wolf.etl.core.filter;


import com.wolf.etl.core.ETLManager;
import com.wolf.etl.core.dialect.AbstractDialect;
import com.wolf.etl.enumeration.SQL_FORMULA;
import com.wolf.vo.BaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by tommy's father on 2017/8/25.
 */
public abstract class AbstractFilter {

    private static Logger logger = LoggerFactory.getLogger(AbstractFilter.class);

    private static final String logger_prefix = "wolf-etl#com.wolf.etl.core#AbstractFilter";

    protected ETLManager manager;

    protected AbstractDialect abstractDialect;

    private static final Object lock = new Object();
    public abstract BaseResult filter(String columnName, String... value);

    public static AbstractFilter getInstance(ETLManager manager,SQL_FORMULA sqlFormula) {
        synchronized (lock) {
            try {
                Class<?> clazz = Class.forName(String.format("%s.%s",getPackageName(), sqlFormula));
                AbstractFilter abstractFilter = (AbstractFilter) manager.getBeanManager().createBean(clazz);
                abstractFilter.manager = manager;
                return abstractFilter;
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    private static final String getPackageName(){
        return new Object(){
            public String getClassForStatic(){
                return this.getClass().getPackage().getName();
            }
        }.getClassForStatic();
    }

    public ETLManager getManager() {
        return manager;
    }

    public void setManager(ETLManager manager) {
        this.manager = manager;
    }

    public AbstractDialect getAbstractDialect() {
        return abstractDialect;
    }

    public void setAbstractDialect(AbstractDialect abstractDialect) {
        this.abstractDialect = abstractDialect;
    }
}
